//
//  TestView.m
//  StaticLibrarySDK
//
//  Created by 李明明 on 15/10/9.
//  Copyright © 2015年 李明明. All rights reserved.
//

#import "TestView.h"
#import "TestVC.h"


@implementation TestView
{
    UIWindow *window;
    UIButton *clickBtn;
}

- (void)makeWindow
{
    window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    window.windowLevel = UIWindowLevelStatusBar + 1;
    [window makeKeyAndVisible];
    
    TestVC *rootVC = [[TestVC alloc] init];
    rootVC.view.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
    UINavigationController *navi = [[UINavigationController alloc] initWithRootViewController:rootVC];
    window.rootViewController = navi;
    navi.navigationBarHidden = YES;
    self.frame = CGRectMake(0, 0, window.frame.size.width - 40, 80);
    self.center = window.center;
    [rootVC.view addSubview:self];
    
}
- (instancetype)initWithCoder:(NSCoder *)coder
{
    self = [super initWithCoder:coder];
    if (self) {
    }
    return self;
}
- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        clickBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    }
    return self;
}
- (NSString *)clickTitle
{
    if (!_clickTitle) {
        _clickTitle = @"clicks";
    }
    return _clickTitle;
}
- (void)show
{
    [clickBtn setTitle:self.clickTitle forState:UIControlStateNormal];
    [self makeWindow];
}
- (IBAction)clickAction:(id)sender
{
    UIButton *button = (UIButton *)sender;
    NSLog(@"%@", button.titleLabel.text);
    [window resignKeyWindow];
    window.windowLevel = UIWindowLevelNormal;
    [self removeFromSuperview];
    window.frame = CGRectZero;
    window = nil;
    [self.delegate clickAction];
}


@end
